import { defineEventHandler } from 'h3';

export function createStatsApi(app) {
  return defineEventHandler(async (event) => {
    if (event.node.req.method === 'GET') {
      const stats = app.database.getStats();
      const proxyStatus = app.proxyServer.getStatus();
      
      return {
        ...stats,
        proxy: proxyStatus,
        websocket: {
          clients: app.webSocketServer.getClientCount()
        },
        uptime: app.isRunning ? Date.now() - app.startTime : 0
      };
    }
  });
}

export function createHealthApi(app) {
  return defineEventHandler(async (event) => {
    return {
      status: 'ok',
      timestamp: Date.now(),
      services: {
        proxy: app.proxyServer.getStatus().running,
        websocket: app.webSocketServer.getClientCount() >= 0,
        database: !!app.database.db,
        api: true,
        systemProxy: app.systemProxyManager.getStatus().isProxySet
      }
    };
  });
} 